// Level

Assault.Level        = {}
Assault.Level.List   = {}
Assault.Level.Loaded = false

// Load

function Assault.Level.Load(ID)
	if (Assault.Level.List[ID]) then
		Assault.Level.Loaded = Assault.Entity:New("prop_world")
		
		// Level
		
		Assault.Level.Loaded:EntitySetVariable("Level", ID)
		
		// Position
		
		Assault.Level.Loaded:EntitySetColor(Color(150, 150, 150, 255))
		Assault.Level.Loaded:EntitySetPosition(Assault.Vector:New(0, 0))
		Assault.Level.Loaded:EntitySetSize(ScrW(), ScrH())
		
		// Merge
		
		table.Merge(Assault.Level.Loaded, Assault.Level.List[ID])
		
		// Create
		
		Assault.Level.Loaded:Create()
		
		// Walls
		
		Assault.Entities.EntitiesQuickCreate("prop_static", Assault.Vector:New(0, 0), 16, ScrH(), Color(100, 100, 100, 255))
		Assault.Entities.EntitiesQuickCreate("prop_static", Assault.Vector:New(16, 0), ScrW() - 16, 16, Color(100, 100, 100, 255))
		Assault.Entities.EntitiesQuickCreate("prop_static", Assault.Vector:New(ScrW() - 16, 16), 16, ScrH() - 16, Color(100, 100, 100, 255))
		Assault.Entities.EntitiesQuickCreate("prop_static", Assault.Vector:New(16, ScrH() - 16), ScrW() - 16, 16, Color(100, 100, 100, 255))
		
		// Return true
		
		return true
	end
	
	// Return false
	
	return false
end

// Spawn entity player

function Assault.Level.SpawnEntityPlayer(Vector, Material, Rotation)
	if (Assault.Level.Player) then Assault.Level.Player:EntityRemove() end
	
	// Player
	
	Assault.Level.Player = Assault.Entity:New("prop_player")
	
	// Position
	
	Assault.Level.Player:EntitySetHealth(100)
	Assault.Level.Player:EntitySetMaterial(Material)
	Assault.Level.Player:EntitySetPosition(Vector)
	Assault.Level.Player:EntitySetSize(16, 16)
	Assault.Level.Player:EntitySetRotation(Rotation)
	
	// Create
	
	Assault.Level.Player:Create()
end

// Destroy

function Assault.Level.Destroy()
	if (Assault.Level.Loaded) then
		Assault.Entity.EntitiesRemoveAll()
		
		// False
		
		Assault.Level.Loaded = false
		
		// Return true
		
		return true
	end
	
	// Return false
	
	return false
end

// New

function Assault.Level:New(ID)
	local Table = {}
	
	// Meta table
	
	setmetatable(Table, self)
	
	// Index
	
	self.__index = self
	
	// ID
	
	Table.ID = ID
	
	// Return table
	
	return Table
end

// Create

function Assault.Level:Create()
	Assault.Level.List[self.ID] = self
end

// Load levels

local Files = file.FindInLua("Assault/Levels/*.lua")

// Loop

for K, V in pairs(Files) do
	include("Assault/Levels/"..V)
end